#!/bin/bash
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.

[[ $CCI_SRC ]] || CCI_SRC=/c/compass-ci

. $CCI_SRC/lib/check_public_network.sh

pkgs=(
	vim
	git
	gcc
	gcc-c++
	make
	ruby
	rubygems
	ruby-devel
	bridge-utils
	qemu
	lvm2
	docker-engine
	dmidecode
	redis
	wget
	busybox
	iproute
	hostname
	libvirt
	curl
	sudo
	iputils
	libxml2-devel
	libxslt-devel
	libvirt-devel
	nmap
	expect
)

wget_rpm()
{
	url=$1
	for i in {1..30}
	do
		wget $url && return 0
		sleep 1
	done
	return 1
}

public_network_ok && {
	yum install -y --skip-broken "${pkgs[@]}"

	# lib64lockfile1 from http://abf-downloads.openmandriva.org/rock/repository/$(arch)/main/release/lib64lockfile1-1.16-1-omv4002.$(arch).rpm
	# lockfile-progs from http://abf-downloads.openmandriva.org/rock/repository/$(arch)/main/release/lockfile-progs-0.1.18-5-omv4002.$(arch).rpm
	wget_rpm https://repo.oepkgs.net/openEuler/compass-ci/cci-deps/lockfile/$(arch)/lib64lockfile1-1.16-1-omv4002.$(arch).rpm
	wget_rpm https://repo.oepkgs.net/openEuler/compass-ci/cci-deps/lockfile/$(arch)/lockfile-progs-0.1.18-5-omv4002.$(arch).rpm

	rpm -i --force lib64lockfile1-1.16-1-omv4002.$(arch).rpm lockfile-progs-0.1.18-5-omv4002.$(arch).rpm
	rm -rf *.rpm
}
